// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import myFilters from './utils/myFilters'
import router from './router'
import WeVue from 'we-vue'
import {getStore} from './utils/storage'
import VueWechatTitle from 'vue-wechat-title'
import 'we-vue/lib/style.css'
import 'swiper/dist/css/swiper.css';
import '../static/css/reset.css'
import global from './utils/global'
import myUtils from './utils/myUtils'

Vue.config.productionTip = false;
Vue.prototype.$global = global;
Vue.prototype.$myUtils = myUtils;

for (let key in myFilters) {  //一定要放在 new Vue之前 注册全局过滤器
  Vue.filter(key, myFilters[key])
}
Vue.use(WeVue);
Vue.use(VueWechatTitle);

router.beforeEach((to, from, next) => {
  let token = getStore("token");
  //console.log(to)
  if (myUtils.isNull(token)) {
    if (!to.meta.isAuth) {
      next();
    } else {
      next({path: '/'})
    }
  } else {
    next();
  }
});

new Vue({
  el: '#app',
  router,
  // components: { App },
  // template: '<App/>',
  render: h => h(App)
});
